package com.yaodian100.ec.member.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;

import com.yaodian100.core.common.entity.BaseEntity;

@Entity
@Table(name = "EC_MEMBER_BONUS")
@NamedQueries( {
		@NamedQuery(name = "Bonus.getDatelineBonus", query = "from Bonus where memberId = :memberId and :nowDate between startDate and expireDate order by expireDate asc "),
		@NamedQuery(name = "Bonus.getLastExpireBonus", query = "from Bonus where memberId = :memberId and (trxAmount - useBonus + refoundBonus ) > 0 and  startDate <= :nowDate and expireDate >= :nowDate order by expireDate asc "),
		@NamedQuery(name = "Bonus.getWaitStartBonus", query = "select sum(trxAmount - useBonus + refoundBonus ) from Bonus where memberId = :memberId and startDate > :nowDate ") })
public class Bonus extends BaseEntity {

	private static final long serialVersionUID = 2873655820533132255L;

	/**
	 * 流水號
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_ec_member_bonus")
	@SequenceGenerator(name = "seq_ec_member_bonus", sequenceName = "SEQ_EC_MEMBER_BONUS")
	@Column(name = "ID")
	private Long id;

	/**
	 * 订单编号
	 */
	@Column(name = "ORDER_ID", length = 17)
	private String orderId;

	/**
	 * 已使用的购物金
	 */
	@Column(name = "USE_BONUS", nullable = false, columnDefinition = "numeric(10,2)")
	private BigDecimal useBonus = new BigDecimal(0.00);

	/**
	 * 退回的购物金
	 */
	@Column(name = "REFOUND_BONUS", nullable = false, columnDefinition = "numeric(10,2)")
	private BigDecimal refoundBonus = new BigDecimal(0.00);

	/**
	 * 会员纪号
	 */
	@Column(name = "MEMBER_ID", nullable = false, length = 10)
	private String memberId;

	/**
	 * 購物金金额
	 */
	@Column(name = "TRX_AMOUNT", nullable = false)
	private BigDecimal trxAmount = new BigDecimal(0.00);

	/**
	 * 購物金產生日期
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "TRX_DATE", nullable = false)
	private Date trxDate;

	/**
	 * 購物金產生類別 ORDER_BONUS:订单赠送积分 ORDER_FEEDBACK：延迟出货补偿 EVENT_POINT:中台赠送(注册送积分)
	 */
	@Column(name = "TRX_TYPE", length = 20, nullable = false)
	private String trxType;

	/**
	 * 交易说明
	 */
	@Column(name = "DESCRIPTION", length = 300, nullable = false)
	private String description;

	/**
	 * 购物金可使用之有效起始日
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "START_DATE", nullable = false)
	private Date startDate;

	/**
	 * 购物金有效结束日期
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "EXPIRE_DATE", nullable = false)
	private Date expireDate;

	public String getDescription() {
		return description;
	}

	public Date getExpireDate() {
		return expireDate;
	}

	public Long getId() {
		return id;
	}

	public String getMemberId() {
		return memberId;
	}

	public String getOrderId() {
		return orderId;
	}

	public BigDecimal getRefoundBonus() {
		return refoundBonus;
	}

	public Date getStartDate() {
		return startDate;
	}

	public BigDecimal getTrxAmount() {
		return trxAmount;
	}

	public Date getTrxDate() {
		return trxDate;
	}

	public String getTrxType() {
		return trxType;
	}

	public BigDecimal getUseBonus() {
		return useBonus;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setExpireDate(Date expireDate) {
		this.expireDate = expireDate;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public void setRefoundBonus(BigDecimal refoundBonus) {
		this.refoundBonus = refoundBonus;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public void setTrxAmount(BigDecimal trxAmount) {
		this.trxAmount = trxAmount;
	}

	public void setTrxDate(Date trxDate) {
		this.trxDate = trxDate;
	}

	public void setTrxType(String trxType) {
		this.trxType = trxType;
	}

	public void setUseBonus(BigDecimal useBonus) {
		this.useBonus = useBonus;
	}
}